﻿using System;
using System.ComponentModel;
using System.Runtime.Serialization;

namespace ImageUploaderComponent.Data{
    [DataContract]
    public abstract class MediaData : INotifyPropertyChanged{
        private string imageTitle;
        private string commentText;
        private int displayOrder;
        private string fileName;
        protected byte[] imageBytes;
        protected bool isEnabled;
        private Uri imageUri;
        private Guid key = Guid.NewGuid();
        public virtual event PropertyChangedEventHandler PropertyChanged;

        [DataMember]
        public Guid Key{
            get { return key; }
            set{
                key = value;
                changeProperty("Key");
            }
        }

        [DataMember]
        public string ImageTitle{
            get { return imageTitle; }
            set{
                imageTitle = value;
                changeProperty("Name");
            }
        }

        [DataMember]
        public string CommentText{
            get { return commentText; }
            set{
                commentText = value;
                changeProperty("Description");
            }
        }

        [DataMember]
        public int DisplayOrder{
            get { return displayOrder; }
            set{
                displayOrder = value;
                changeProperty("DisplayOrder");
            }
        }

        [DataMember]
        public string FileName{
            get { return fileName; }
            set
            {
                fileName= value;
                changeProperty("FileName");
            }
        }

        [DataMember]
        public byte[] ImageBytes{
            get { return imageBytes; }
            set{
                imageBytes = value;
                changeProperty("ImageBytes");
            }
        }

        [DataMember]
        public bool IsEnabled{
            get { return isEnabled; }
            set{
                if (value != isEnabled){
                    changeProperty("IsEnabled");
                }
                isEnabled = value;
            }
        }



        public Uri ImageUri{
            get { return imageUri; }
            set{
                if (value != imageUri){
                    changeProperty("ImageUri");
                }
                imageUri = value;
            }
        }
		

        public override string ToString() {
            return ImageTitle;
        }

        protected void changeProperty(string propertyName){
            if(PropertyChanged != null){
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}